package com.nuit.cxl.mvcdemo.controller;

import com.nuit.cxl.mvcdemo.dao.Person;
import com.nuit.cxl.mvcdemo.dao.Teacher;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.regex.Pattern;

@Controller
public class BiliController {


    @Operation
    @PutMapping("/biliview")
    public String getBili(@RequestParam String view, Model model){
        //这里返回的就是 view ，bili.html  这个文件
        model.addAttribute("name",view);
        return "bili";
    }

    @GetMapping("/bili")
    @ResponseBody
    @Operation
    public Person getBili2(@RequestBody Person person){
        //去数据库里面查询数据
        //把他放在里面
        ArrayList<String> address = new ArrayList<>();
        address.add("guangdongd");
        address.add("foshan");
        Teacher teacher = new Teacher();
        teacher.setName("name");
//        Person person = new Person(name, id, address, teacher);

        return person;
    }

    @GetMapping("/bilibili/{id}")
    @ResponseBody
    @Operation
    public Person getBili2(@PathVariable Integer id, @RequestParam Integer age){
        //去数据库里面查询数据
        //把他放在里面
        ArrayList<String> address = new ArrayList<>();
        address.add("guangdongd");
        address.add("foshan");
        Teacher teacher = new Teacher();
        teacher.setName("name");
        Person person = new Person("zhangshan", age, address, teacher, null);

        return person;
    }

    @GetMapping("/bili/{id}")
    @ResponseBody
    @Operation
    public Person getBili2(@PathVariable Integer id, @RequestParam @DateTimeFormat(pattern = "yyyy/MM/dd") Date date){
        //去数据库里面查询数据
        //把他放在里面
        ArrayList<String> address = new ArrayList<>();
        address.add("guangdongd");
        address.add("foshan");
        Teacher teacher = new Teacher();
        teacher.setName("name");
        Person person = new Person("zhangshan", 18, address, teacher, date);

        return person;
    }
}
